package slidingwindow.leetcode_3;

public class ArraySolution {
    public int lengthOfLongestSubstring(String s) {
        int[] arr = new int[128];
        for (int i = 0; i < arr.length; i++){
            arr[i] = -1;
        }
        int maxLen = 0;
        int left = 0;
        for (int right = 0; right < s.length(); right++) {
            if (arr[s.charAt(right)] > -1) {
                left = Math.max(left, arr[s.charAt(right)] + 1);
            }
            maxLen = Math.max(maxLen, right - left + 1);
            arr[s.charAt(right)] = right;
        }
        return maxLen;
    }

    public static void main(String[] args) {
        new ArraySolution().lengthOfLongestSubstring(" ");
    }
}
